package day8;

//实现Runnable接口  实现run()
public class TestRunnable implements Runnable {
    @Override   //线程的执行逻辑
    public void run() {
        String name = Thread.currentThread().getName();
        for (int i = 0; i < 10; i++) {
            System.out.println(name + " " + i);
        }
    }

    public static void main(String[] args) {
        //不是线程对象(跟Thread没关系)    只是线程执行规则
        TestRunnable test = new TestRunnable();
        Thread thread1 = new Thread(test, "DemoA");
        Thread thread2 = new Thread(test, "B");
        Thread thread3 = new Thread(() -> {
            String name = Thread.currentThread().getName();
            for (int i = 10; i < 20; i++) {
                System.out.println(name + " " + i);
            }
        }, "C");
        //thread1和thread2才是线程对象
        thread1.start();
        thread2.start();
        thread3.start();

    }
}
